import { _result } from '../../common/api/test'
const app = getApp()
Page({
  data: {
    id: null,
    userinfo: null,
    score: 0,
    list: [],
    Msg: "",
    color: "#E82F32"
  },
  getResult() {
    app.loading('加载中')
    let memberid = wx.getStorageSync('memberid')
    _result(memberid, this.data.id).then(res => {
      wx.hideLoading()
      if (res.data.IsSuccess) {
        let list = res.data.Data.Data
        let score = res.data.Data.Sourt
        let Msg = res.data.Msg
        if (Msg == "很遗憾，您未通过本次考试") {
          this.setData({ color: "#cecece" })
        }
        this.setData({
          list,
          score,
          Msg
        })
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.data.Msg,
          showCancel: false,
          success: r => {
            if (r.confirm) {
              wx.navigateBack()
            }
          }
        })
      }
    }).catch(err => {
      wx.hideLoading()
      console.log(err)
      wx.showModal({
        title: '对不起',
        content: '请求错误，请稍后再试',
        showCancel: false
      })
    })
  },
  onLoad(options) {
    this.data.id = options.id
    this.setData({
      id: this.data.id
    })
  },
  onReady() { },
  onShow() {
    if (app.store.userinfo) {
      this.setData({
        userinfo: app.store.userinfo
      }, () => {
        this.getResult()
      })
    } else {
      app.loading('加载中')
      app.launch().then(res => {
        wx.hideLoading()
        this.data.userinfo = app.store.userinfo = res
        this.setData({
          userinfo: this.data.userinfo
        }, () => {
          this.getResult()
        })
      }).catch(err => {
        wx.hideLoading()
        console.log(err)
      })
    }
  },
  onHide() { },
  onUnload() { },
  onPullDownRefresh() { },
  onReachBottom() { },
  onShareAppMessage() { }
})